import Mock from 'mockjs'
const url = require('url')
let email = 'admin'
let password = 'admin'
let username = 'admin'
Mock.mock('http://192.168.43.118:8080/login', 'post', function (options) {
  let status
  let body = '?'
  body += options.body
  let query = url.parse(body, true).query
  if (query.email == email && query.password == password) {
    return { status: 1, username: username }
  } else {
    return { status: 0, username: username }
  }
})
Mock.mock('http://192.168.43.118:8080/register', 'post', function (options) {
  let status
  let body = '?'
  body += options.body
  let query = url.parse(body, true).query
  console.log(query);
  if (query.email != email) {
    email = query.email
    password = query.password
    return { status: 1, username: username }
  } else {
    return { status: 0, username: username }
  }
})
Mock.mock(RegExp(/http:\/\/192.168.43.118:8080\/search\?filename = /), function (options) {
  let files = []
  let filename = url.parse(options.url, true).query.filename
  files = [
    {
      filename: 'test.png',
      fileurl: 'http://localhost:8080/img/test2.png'
    },
    {
      filename: 'test.png',
      fileurl: 'http://localhost:8080/img/test2.png'
    },
    {
      filename: 'test.png',
      fileurl: 'http://localhost:8080/img/test2.png'
    }
  ]
  return files
})
Mock.mock('http://192.168.43.118:8080/search', function () {
  return [
    {
      filename: 'image.jpg',
      fileurl: 'http://localhost:8080/img/test2.png'
    }, {
      filename: 'text.text',
      fileurl: 'http://localhost:8080/img/test2.png'
    }, {
      filename: 'img.png',
      fileurl: 'http://localhost:8080/img/test2.png'
    }, {
      filename: 'vue.zip',
      fileurl: 'http://localhost:8080/img/test2.png'
    },
  ]
})